<table width="100%"  border="0" cellspacing="1" cellpadding="3">
<?php 
    $CRequest = "SELECT 
					ccenter_requests.Ref,
					ccenter_requests.RefUser,
					ccenter_requests.Observations,
					hcce_status.name AS Status,
					ccenter_requests.TimeCreated,
					ccenter_requests.TimeDelivered,
					ccenter_requests.TimeReceived,
					ccenter_requests.TimeAproval,
					ccenter_requests.RefAproval AS Aproval,
					ccenter_requests.RefSupervisor,
					main_offices.name AS Office,
					main_users.name AS User
				FROM ccenter_requests
				INNER JOIN main_offices ON main_offices.ref = ccenter_requests.RefOffice
				INNER JOIN main_users ON main_users.ref = ccenter_requests.RefUser
				INNER JOIN hcce_status ON hcce_status.ref = ccenter_requests.Status
				WHERE ccenter_requests.RefUser = {$_SESSION['UtID']}
				ORDER BY ccenter_requests.TimeCreated DESC, ccenter_requests.Ref DESC LIMIT 0,1";
	$Request = $GLOBALS['CONN']->db_array($CRequest); 
	for ($f = 1; $f <= $Request[0]; $f++) { ?>
<form action="?action=requests" name="UpdateRequest" method="post" runat="server" />
  <tr>
    <td width="25%" rowspan="4" bgcolor="#ACB1CC"><div align="right"><img src="<?php echo $GLOBALS['GFX'];?>CentrodeCustos/requests.png"></div></td>
    <td bgcolor="#ACB1CC"><input name="Ref" type=text value="<?php echo $Request[1]['Ref'];?>" size="6" readonly="">
    </td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Cliente:
      <?php echo $Request[1]['Office'];?>      </td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Data:
      <?php echo $Request[1]['TimeCreated'];?></td>
  </tr>
  <tr>
    <td bgcolor="#ACB1CC">Por:
    <?php echo $Request[1]['User'];?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td valign="top"><div align="right">ObservaÇ&otilde;es</div></td>
    <td width="75%"><textarea name="Observations" cols="60" rows="4"><?php echo $Request[1]['Observations'];?></textarea></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td colspan="2">
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="1">
      <tr>
        <td colspan="7"><strong>Artigos a solicitar</strong> </td>
        </tr>
      <tr bgcolor="#FFFFFF">
        <td><div align="center">CÓdigo</div></td>
        <td><div align="center">Tipo</div></td>
        <td width="50%"><div align="center">Artigo</div></td>
        <td><div align="center">Quant.</div></td>
        <td><div align="center">Uso</div></td>
        <td>Finalidade</td>
        <td><div align="center"></div></td>
      </tr>
      <tr bgcolor="#E9ECED">
        <td><input name="REFER" type="text" size="8"></td>
        <td><select name="TYPE" id="TYPE" onChange="document.UpdateRequest.submit();">
          <option value="1">Produto</option>
          <option value="2">ServiÇo</option>
          <option value="3">Outros</option>
        </select></td>
        <td>
		<select name="Article" id="Article">
              <option value=""> </option>
              <?php
	   $CLista = "SELECT Ref, Description
	  			FROM ccenter_econ";
		$Lista = $GLOBALS['CONN']->db_array($CLista);
		for($a = 1; $a <= $Lista[0]; $a++) {
		print '<option value="'.$Lista[$a]['Ref'].'">'.$Lista[$a]['Description'].'</option>';
		}
		?>
            </select></td>
        <td><input name="Quant" type="text" id="Quant" value="1" size="6" maxlength="9"></td>
        <td><select name="UseTYPE" id="UseTYPE">
          <option value="1">Interno</option>
          <option value="2">Externo</option>
        </select></td>
        <td><select name="Use" id="Use">
          <option value="1">Interno</option>
          <option value="2">Externo</option>
        </select></td>
        <td><input name="AddArticle" value="" type="submit" id="AddArticle" class="InsertButton"></td>
      </tr>
	 <?php 
    $CArticles = "SELECT 
					ccenter_econ.REFER,
					ccenter_econ.Description,
					ccenter_econ.TYPE,
					ccenter_requestarticles.Quantity,
					ccenter_requestarticles.seTYPE,
					ccenter_requestarticles.se
				FROM ccenter_requestarticles
				LEFT OUTER JOIN ccenter_econ ON ccenter_econ.Ref = ccenter_requestarticles.RefArticle
				WHERE ccenter_requestarticles.RefRequest = {$Request[1]['Ref']}";
	$Articles = $GLOBALS['CONN']->db_array($CArticles); 
	for ($a = 1; $a <= $Articles[0]; $a++) {
	   echo '<tr bgcolor="#FFFFFF">
        <td>'.$Articles[$a]['REFER'].'</td>
        <td>'.$Articles[$a]['TYPE'].'</td>
        <td>'.$Articles[$a]['Description'].'</td>
        <td>'.round($Articles[$a]['Quantity']).'</td>
        <td>'.$Articles[$a]['seTYPE'].'</td>
        <td>'.$Articles[$a]['se'].'</td>
      </tr>';
	  } ?>
    </table></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>Estado: </td>
    <td><?php echo $Request[1]['Status'];?></td>
  </tr>
  <?php if ($Request[1]['TimeAproval'] =! null) { ?>
  <tr bgcolor="#F2F2F2">
    <td> Aprovação: </td>
    <td><?php echo $Request[1]['Aproval'].', a'.$Request[1]['TimeAproval'];?></td>
  </tr>
  <?php } 
  		if ($Request[1]['TimeDelivered'] != null) { ?>
  <tr bgcolor="#F2F2F2">
    <td>Data Para Entrega </td>
    <td><?php echo $Request[1]['TimeAproval'];?></td>
  </tr>
  <?php }
  if ($Request[1]['TimeDelivered'] != null && $Request[1]['TimeReceived'] == null) { ?>
  <tr bgcolor="#F2F2F2">
    <td valign="top">Confirmar Entrega:</td>
    <td><input name="DateReceived" type="text" id="DateReceived" onFocus="this.select();lcs(this)" 
	  onClick="event.cancelBubble=true;this.select();lcs(this)" 
	  value="<?php echo $_POST['TimeReceived'];?>" size="8" maxlength="10" /></td>
  </tr>
  <?php } else { ?>
  <tr bgcolor="#F2F2F2">
    <td valign="top">Data de Entrega:</td>
    <td><?php echo $Request[1]['TimeReceived'];?></td>
  </tr>
  <?php } ?>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td><input type="submit" name="UpdateRequest" value="Submeter"></td>
  </tr>
  </form>
  <?php } ?>
</table>
